﻿@using HGShare.Site
@using HGShare.Site.Config
@using HGShare.VWModel
@using Webdiyer.WebControls.Mvc
@model PagedList<CommentVModel>
@{
    ViewBag.Title = "评论列表";
    Layout = "~/Views/Shared/_HContentLayout.cshtml";
}
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>评论列表</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form action="@Url.Action("Index", "Comments")" method="GET">
                        <div class="row">
                            <div class="col-sm-5 m-b-xs">
                                <div class="btn-group hidden-xs" role="group">
                                    <a href="@Url.Action("Add","Comments")" class="btn btn-outline btn-default" title="添加">
                                        <i class="fa fa-pencil-square" aria-hidden="true"></i> 添加
                                    </a>
                                    <button class="btn btn-default btn-outline" type="button" name="refresh" title="刷新" id="pagereload">
                                        <i class="fa fa-refresh"></i> 刷新
                                    </button>
                                    <button type="button" class="btn btn-outline btn-default" id="deletessubmit" title="删除选中项">
                                        <i class="fa fa-trash" aria-hidden="true"></i> 删除
                                    </button>
                                    <button type="button" class="btn btn-outline btn-default" id="verifiedsubmit" title="通过审核选中项">
                                        <i class="fa fa-check" aria-hidden="true"></i> 通过
                                    </button>
                                    <button type="button" class="btn btn-outline btn-default" id="noverifiedsubmit" title="不通过审核选中项">
                                        <i class="fa fa-close" aria-hidden="true"></i> 拒绝
                                    </button>
                                </div>
                            </div>
                            <div class="col-sm-4 m-b-xs">
                                <!--其它搜索条件-->
                            </div>
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <input type="hidden" name="page" value="1" />
                                    <input type="text" placeholder="请输入关键词" class="input-sm form-control">
                                    <span class="input-group-btn">
                                        <button type="submit" class="btn btn-sm btn-primary"> 搜索</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </form>
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>
                                        <div class="checkbox checkbox-inline checkbox-primary">
                                            <input type="checkbox" value="0" id="selectitem" />
                                            <label for="selectitem"></label>
                                        </div>
                                    </th>
                                    <th>编号</th>
                                    <th>文章</th>
                                    <th>评论用户Id</th>
                                    <th>评论内容</th>
                                    <th>评论者Ip</th>
                                    <th>用户UA信息</th>
                                    <th>审核状态</th>
                                    <th>是否置顶</th>
                                    <th>最后修改时间</th>
                                    <th>创建时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (CommentVModel item in Model)
                                {
                                    <tr>
                                        <td>
                                            <div class="checkbox checkbox-inline checkbox-primary">
                                                <input type="checkbox" value="@item.Id" id="item_@item.Id" name="item" class="form-control" />
                                                <label for="item_@item.Id"></label>
                                            </div>
                                        </td>

                                        <td>@item.Id</td>
                                        <td><a href="@Url.BbsWebAction("Detail", "Article",new{aid=item.AId})" target="_blank">@item.ArticleTitle</a></td>
                                        <td>@item.NickName</td>
                                        <td><a href="javascript:;" data-id="@item.Id" class="showcontent">查看</a></td>
                                        <td>@item.IP</td>
                                        <td><a href="javascript:;" onclick="layer.alert('@item.UserAgent')">查看</a></td>
                                        <td>
                                            <input type="checkbox" data-id="@item.Id" class="state-switch" @(item.State == 1 ? "checked" : "") title="@(item.State == 1 ? "已通过" : item.State==2?"未通过":"未审核")" />
                                            <a class="@((item.State == 2 && !string.IsNullOrEmpty(item.RefuseReason)) ? "" : "hidden")" id="state-refusereason@(item.Id)" href="javascript:;" data-reason="@item.RefuseReason" onclick="layer.alert($(this).attr('data-reason'))">原因</a>
                                        </td>
                                        <td>
                                            <span class="label label-@(item.IsStick ? "success" : "default")">@(item.IsStick ? "是" : "否")</span>
                                        </td>
                                        <td>@item.CreateTime</td>
                                        <td>@item.LastEditTime</td>
                                        <td>
                                            <a class="btn btn-info btn-sm" href="@Url.Action("Edit","Comments")?Id=@item.Id"><i class="fa fa-paste"></i> 编辑</a>
                                            <button class="btn btn-warning btn-sm delete_btn" type="button" data-id="@item.Id">
                                                <i class="fa fa-warning"></i> <span class="bold">删除</span>
                                            </button>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>

                </div>
            </div>
        </div>

    </div>
    <div class="row">
        <div class="col-sm-6">
            <div class="dataTables_info">共 @Model.TotalItemCount 项 @Model.TotalPageCount 页，当前第 @Model.CurrentPageIndex 页</div>
        </div>
        <div class="col-sm-6">
            <div class="dataTables_paginate paging_simple_numbers">
                <ul class="pagination">
                    @Html.Pager(Model, PageConfig.BackstageOptions)
                </ul>
            </div>
        </div>
    </div>
</div>
@section script_header
{
    <!--切换开关插件-->
    <link href="@Url.StaticFile("~/hplus/css/plugins/switchery/switchery.css")" rel="stylesheet">
}
@section script_footer
{
    <!--切换开关插件-->
    <script type="text/javascript" src="@Url.StaticFile("~/hplus/js/plugins/switchery/switchery.js")"></script>
    <script type="text/javascript">
        $(function() {
            /*通用删除操作*/
            ListTools.Delete.Init({ url: "@Url.Action("Delete", "Comments")", btn: ".delete_btn" });
            /*通用多选删除操作*/
            ListTools.Deletes.Init({ url: "@Url.Action("Deletes", "Comments")", btn: "#deletessubmit", itemname: "item" });
            /*选择操作*/
            ListTools.SelectBox.Init({ btn: "#selectitem", itemname: "item" });
            /*刷新操作*/
            ListTools.PageReload.Init({ btn: "#pagereload" });
            /***************************************************/
            /*
            *状态开关 开 state=1 关 state=2
            *关闭时输入 理由
            */
            var elems = Array.prototype.slice.call(document.querySelectorAll('.state-switch'));
            elems.forEach(function(checkbox) {
                var switchery = new Switchery(checkbox);
                checkbox.onchange = function() {
                    var id = $(this).attr("data-id");
                    this.checked ? tongGuo(id) : juJue(id);
                };
            });
            /*通过*/
            var tongGuo = function(id) {
                hgajax.postNoAlert("@Url.Action("Verified", "Comments")", { id: id, state: true }, function() {
                    $("#state-refusereason" + id).addClass("hidden");
                });
            };
            /*拒绝*/
            var juJue = function(id) {
                hgajax.postNoAlert("@Url.Action("Verified", "Comments")", { id: id, state: false, reason: escape("暂无！") });
                layer.prompt({ title: '输入拒绝通过原因', formType: 2 }, function(text, index) {
                    layer.close(index);
                    hgajax.postNoAlert("@Url.Action("Verified", "Comments")", { id: id, state: false, reason: escape(text) }, function() {
                        $("#state-refusereason" + id).attr("data-reason", text);
                        $("#state-refusereason" + id).removeClass("hidden");
                    });
                });
            };
            /***************************************************/
            //批量审核
            var tongGuos = function() {
                var ids = ListTools.SelectBoxValues("item");
                if (ids.length == 0) {
                    layer.msg("请选择数据！", { shift: 6 });
                    return;
                }
                var conf = layer.confirm(
                    '确定执行审核通过操作？',
                    { btn: ['确定', '取消'] },
                    function() {
                        layer.close(conf);
                        hgajax.post("@Url.Action("Verifieds", "Comments")", { ids: ids, state: true }, tabTools.TabPageReload);

                    }
                );

            };
            var juJues = function() {
                var ids = ListTools.SelectBoxValues("item");
                if (ids.length == 0) {
                    layer.msg("请选择数据！", { shift: 6 });
                    return;
                }
                var conf = layer.confirm(
                    '确定执行拒绝审核通过操作？',
                    { btn: ['确定', '取消'] },
                    function() {
                        layer.close(conf);
                        layer.prompt({ title: '输入拒绝通过原因', formType: 2 }, function(text, index) {
                            layer.close(index);
                            hgajax.post("@Url.Action("Verifieds", "Comments")", { ids: ids, state: false, reason: escape(text) }, tabTools.TabPageReload);
                        });
                    }
                );
            };

            $("#verifiedsubmit").on("click", tongGuos);
            $("#noverifiedsubmit").on("click", juJues);

            /****************************************************/
            //查看内容
            function ShowContent(id) {
                layer.open({
                    type: 2,
                    title: '内容',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['50%', '50%'],
                    content: '@Url.Action("Content", "Comments")?id=' + id
                });
            }
            $('.showcontent').on("click", function() {
                ShowContent($(this).attr("data-id"));
            });
            /******************************************************/
        })
    </script>
}











